package com.hfi.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017/12/1.
 */
@Component
@Aspect
public class Audience {

    @Pointcut("execution(* com.hfi.aop.Performance.perform(..))")
    public void performance(){}

    @Around("performance()")
    public Object watchPerformance(ProceedingJoinPoint jp){
        try {
            System.out.println("Silencing cell phones");
            System.out.println("Taking seats");
            Object proceed = jp.proceed();
            System.out.println("CLAP CLAP CLAP");
            return proceed;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("Demanding a refund");
        }
        return "error";
    }
}
